package com.hobby4fun.flex.utils
{
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;
	
	
	public class HttpServiceUtil
	{
		/**
		 * Get XML content from URL
		 * 
		 * @param urlStr : String eg 'data/myFile.xml' or 'http://someServer/rootContext/etc/myFile.xml'
		 * @param responseHandler : Function to handle response in e4x format
		 * @param faultHandler : Function to handle error
		 * @param params : Object eg { abc: "123", def: "456" };
		 * @return HttpService
		 */		
		public static function xmlFileReader(urlStr:String, 
			responseHandler:Function, faultHandler:Function, params:Object=null) : HTTPService
		{
			var service:HTTPService = new HTTPService();
			service.url = urlStr;
			service.method = "GET";
			service.resultFormat = "e4x";
			service.useProxy = false;
			service.addEventListener(FaultEvent.FAULT, faultHandler);
			service.addEventListener(ResultEvent.RESULT, responseHandler);
			return service;
		}

	}
}